package com.baizhi.zyj.controller;

import com.baizhi.zyj.dto.*;
import com.baizhi.zyj.entity.Category;
import com.baizhi.zyj.service.CategoryService;
import com.baizhi.zyj.vo.CategoryQueryByLevelsVo;
import com.baizhi.zyj.vo.CategoryStaVo;
import com.baizhi.zyj.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@CrossOrigin
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("queryOnePage")
    @ResponseBody
    public CategoryVo queryOnePage(@RequestBody CategoryDto categoryDto){
       return categoryService.queryOnePage(categoryDto.getPage(),categoryDto.getPageSize());
    }


    @RequestMapping("queryTwoPage")
    @ResponseBody
    public CategoryVo queryTwoPage(@RequestBody CategoryTwoDto categoryTwoDto){
        return categoryService.queryTwoPage(categoryTwoDto.getPage(),categoryTwoDto.getPageSize(),categoryTwoDto.getCategoryId());
    }

    @RequestMapping("add")
    @ResponseBody
    public CategoryStaVo add(@RequestBody CategoryAddDto categoryAddDto){
        return categoryService.add(categoryAddDto);
    }

    @RequestMapping("delete")
    @ResponseBody
    public CategoryStaVo delete(@RequestBody CategoryDeleteDto categoryDeleteDto){
        return categoryService.delete(categoryDeleteDto);
    }

    @RequestMapping("queryById")
    @ResponseBody
    public Category queryById(int id){
        return categoryService.queryById(id);
    }

    @RequestMapping("update")
    @ResponseBody
    public CategoryStaVo update(@RequestBody CategoryUpdateDto categoryUpdateDto){
        System.out.println(categoryUpdateDto);
        return categoryService.update(categoryUpdateDto);
    }

    @RequestMapping("queryByLevelsCategory")
    @ResponseBody
    public List<CategoryQueryByLevelsVo> queryByLevelsCategory(int levels){
        return categoryService.queryByLevelsCategory(levels);
    }
}
